package com.ss.android.newmedia.a;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ss.android.article.browser.R;

@Deprecated
public final class PopupToast {
    private Dialog mPopupToastDialog;
    private ImageView iconIv;
    private TextView textTv;
    private View contentView;
    private boolean isDestroyed;
    private Handler mHandler;
    private Runnable mDismissRunnable;

    public PopupToast(Context context) {
        this.isDestroyed = false;
        this.mHandler = new Handler();
        this.mDismissRunnable = new Runnable() {
            public final void run() {
                PopupToast.this.dismiss();
            }
        };
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        this.mPopupToastDialog = new Dialog(context, R.style.popuptoast_dialog);
        try {
            View view = layoutInflater.inflate(R.layout.popup_toast, null);
            this.contentView = view;
            this.iconIv = view.findViewById(com.ss.android.article.browser.R.id.icon);
            this.textTv = view.findViewById(com.ss.android.article.browser.R.id.text);
            this.mPopupToastDialog.setContentView(this.contentView);
            this.mPopupToastDialog.getWindow().addFlags(8);
            this.mPopupToastDialog.getWindow().addFlags(32);
            this.mPopupToastDialog.getWindow().addFlags(16);
            this.mPopupToastDialog.getWindow().setLayout(-2, -2);
            this.mPopupToastDialog.getWindow().setGravity(17);
        } catch (Throwable throwable) {
        }
    }

    public final void onDestroy() {
        if (!this.isDestroyed) {
            this.mHandler.removeCallbacks(this.mDismissRunnable);
            this.dismiss();
            this.isDestroyed = true;
        }
    }

    public final void showToast(int imageResId, int contentResId, String content, int duration, int gravity) {
        boolean hasImage = false;
        boolean hasTxt = true;
        if (!this.isDestroyed && duration > 0) {
            if (imageResId > 0) {
                this.iconIv.setImageResource(imageResId);
                this.iconIv.setVisibility(View.VISIBLE);
                hasImage = true;
            } else {
                this.iconIv.setVisibility(View.GONE);
            }

            if (contentResId > 0) {
                this.textTv.setText(contentResId);
            } else if (!android.support.design.a.isTextEmpty(content)) {
                this.textTv.setText(content);
            } else {
                hasTxt = false;
            }

            if (!hasTxt && !hasImage) {
                return;
            }

            this.mHandler.removeCallbacks(this.mDismissRunnable);
            this.dismiss();
            try {
                this.mPopupToastDialog.getWindow().setGravity(gravity);
                this.mPopupToastDialog.show();
                this.mHandler.postDelayed(this.mDismissRunnable, duration);
            } catch (Exception exception) {
            }
        }
    }

    public final void showToast(String content) {
        this.showToast(0, 0, content, 1500, 17);
    }

    public final void showToast(int imageResId, int contentResId) {
        this.showToast(imageResId, contentResId, null, 1500, 17);
    }

    public final void dismiss() {
        if (!this.isDestroyed) {
            try {
                if (!this.mPopupToastDialog.isShowing()) {
                    return;
                }

                this.mPopupToastDialog.dismiss();
            } catch (Exception v0) {
            }
        }
    }
}

